package com.example.design.filter.context;

import com.example.design.filter.enums.ScheduleTagEnum;
import com.example.design.filter.model.ActScheduleUserTagDO;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Date;

@Getter
@Setter
@Accessors(chain = true)
public class ScheduleTag {

    private ScheduleTagEnum tag;

    private Boolean forever;

    private Date startTime;

    private Date endTime;

    public ScheduleTag(ScheduleTagEnum tag, Boolean forever) {
        this.tag = tag;
        this.forever = forever;
    }

    public ScheduleTag(ScheduleTagEnum tag, Boolean forever, Date startTime, Date endTime) {
        this.tag = tag;
        this.forever = forever;
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public ScheduleTag(ActScheduleUserTagDO tagDO) {
        this.tag = ScheduleTagEnum.getByDictCode(tagDO.getTagCode());
        this.forever = tagDO.getForever() != null && tagDO.getForever();
        this.startTime = tagDO.getStartTime();
        this.endTime = tagDO.getEndTime();
    }

    public boolean valid(ScheduleTagEnum tag, Date date) {
        if (!this.tag.equals(tag)) {
            return false;
        }
        if (this.forever) {
            return true;
        }
        return this.startTime.compareTo(date) <= 0 && this.endTime.compareTo(date) >= 0;
    }
}
